package com.zhongfeng.api.modules.white;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class updateWhite {
    public static void main(String[] args) throws IOException {
        //保留几位(默认为4)
        int num = 4;
        //存储结果集
        List<String> result = new ArrayList<>();
        String filename = "C:\\Users\\84361\\Desktop\\白名单\\新建 文本文档.txt";
        Scanner sc = new Scanner(new FileReader(filename));
        String next = sc.next();
        String[] split = next.split(",");
        List<String> numbers = Arrays.asList(split);
        for (String number : numbers) {
            String substring = number.substring(0, num);
            if (!result.contains(substring)){
                result.add(substring);
            }
        }
        FileWriter fw = new FileWriter("C:\\Users\\84361\\Desktop\\白名单\\转换号码集合(保留"+num+"位).txt");
        for (int i = 0; i < result.size(); i++) {
            if (i == 0){
                fw.write(result.get(i));
            }else {
                fw.write(","+result.get(i));
            }
        }
        fw.flush();
        fw.close();
    }
}
